module Fighter {

	/**
	 * 准备Ui--郭启航
	 */
	export class PrepareUI extends eui.Component {

		constructor() {
			super();
			this.skinName = "resource/assets/PlaneE/PrepareUI.exml";
			this.Music_HSlide.value = 5;
			this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
			this.addEventListener(egret.Event.ENTER_FRAME, this.Show, this);
			this.addEventListener(egret.Event.ENTER_FRAME, this.twinkle, this);
		}
		/**字幕跳出效果*/
		private SubtitleJumped: Fighter.SubtitleJumped = new Fighter.SubtitleJumped();
		//	public www: fighter.StartUI = new fighter.StartUI();
		/**购买敌人*/
		private BuyEnemy: eui.Image;
		 /**购买僚机*/
		private BuyGuard: eui.Image;
		// /**升级*/
		// private Update: eui.Button;
		// /*投资*/
		// private Invest: eui.Button;
		/**是否显示准备按钮*/
		public static isReadyShow: boolean = false;
		/**准备完成按钮 */
		public Reday: eui.Image;
		/**金币提示*/
		private Prepare_Moneyshow: eui.BitmapLabel;
		/**时间提示*/
		public Timeshow: eui.BitmapLabel;
		/**投资100*/
		public Invest_100: eui.Group;
		/**投资500*/
		public Invest_500: eui.Group;
		/**投资1000*/
		public Invest_1000: eui.Group;
		// /**升级血量*/
		// public Update_Hp: eui.Group;
		// /**升级攻击*/
		// public Update_ATK: eui.Group;

		/**切换防守场景*/
		private AddDefenseUI: eui.Group;
		/**切换防守Bool*/
		public is_AddDefenseUI: boolean;
		/**切换敌方防守UI按钮*/
		public AddEnemyDefenseUI: eui.Group;
		/**切换敌方防守UIBool*/
		public IS_AddEnemyDefenseUI: boolean;

		/**音量滑条*/
		public Music_HSlide: eui.HSlider;
		/**	购买的僚机 */
		public Is_BuyEnemy: boolean = false;
		public Is_BuyGuard: boolean = false;
		// public Is_Update: boolean;
		// public Is_Invest: boolean;
		public Is_Reday: boolean;
		public AirBattleUI: Fighter.AirBattleUI = new Fighter.AirBattleUI();
		/**音量s*/
		public static MusicValue: number =1;
		/**音量弹窗按钮*/
		public Prepare_Music: eui.Image;
		/**音乐弹窗*/
		public Music_group: eui.Group;
		/**关闭音乐弹窗*/
		public Close_Music: eui.Image;
		/**播放音乐Bool值*/
		public static PlayMusciBool: boolean = false;
		/**切换敌机防守场景的闪烁按钮背景 */
		public Enemy_bg: eui.Image;
		/**切换我方防守场景的闪烁按钮背景 */
		public Defense_bg: eui.Image;

		/**每帧显示 */
		public Show() {
			this.Timeshow.text =GameUtil.PlayerMessage.createMsg().time.toString();
			this.Prepare_Moneyshow.text =GameUtil.PlayerMessage.instance.money.toString();
			PrepareUI.MusicValue = this.Music_HSlide.value / 10;		
			if (PrepareUI.isReadyShow) {
				this.Reday.visible = true;
			}

		}
		public onAddToStage() {
			this.BuyEnemy.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addBuyEnemy, this);
			this.BuyGuard.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addBuyGuard, this);

			this.AddDefenseUI.addEventListener(egret.TouchEvent.TOUCH_TAP, this.AddDefense, this);
			this.Reday.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addReday, this);
		//	this.BuyEnemy.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addBuyEnemy, this);
			this.Invest_100.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Invest100, this);
			this.Invest_500.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Invest500, this);
			this.Invest_1000.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Invest1000, this);
			//this.Update_Hp.addEventListener(egret.TouchEvent.TOUCH_TAP, this.UpdateHp, this);
			//this.Update_ATK.addEventListener(egret.TouchEvent.TOUCH_TAP, this.UpdateATK, this);
			this.AddEnemyDefenseUI.addEventListener(egret.TouchEvent.TOUCH_TAP, this.AddEnemyDefense, this);
			this.Prepare_Music.addEventListener(egret.TouchEvent.TOUCH_TAP, this.AddMusic_group, this);
			this.Close_Music.addEventListener(egret.TouchEvent.TOUCH_TAP, this.CloseMusic_group, this);
			this.Reday.visible = false;
		}
		/**购买敌机*/
		public addBuyEnemy() {
			this.Is_BuyEnemy = true;
		}
		/**购买僚机 护卫 */
		public addBuyGuard() {
			this.Is_BuyGuard = true;
		}
		/**添加准备完成*/
		public addReday() {
			if (Defense.allowToNextTurn) {
				this.Is_Reday = true;
			}
		}
		/**投资100*/
		public Invest100() {
			if (GameUtil.PlayerMessage.instance.money >= 100) {
				GameUtil.PlayerMessage.instance.money -= 100;
				GameUtil.PlayerMessage.instance.investment += 100;
				this.SubtitleJumped.SubtitleJumped(100, this.Invest_100);
				this.addChild(this.SubtitleJumped);
			}
		}
		/**投资500*/
		public Invest500() {
			if (GameUtil.PlayerMessage.instance.money >= 500) {
				GameUtil.PlayerMessage.instance.money -= 500;
				GameUtil.PlayerMessage.instance.investment += 500;
				this.SubtitleJumped.SubtitleJumped(500, this.Invest_500);
				this.addChild(this.SubtitleJumped);
			}
		}
		public Invest1000() {
			if (GameUtil.PlayerMessage.instance.money >= 1000) {
				GameUtil.PlayerMessage.instance.money -= 1000;
				GameUtil.PlayerMessage.instance.investment += 1000;
				this.SubtitleJumped.SubtitleJumped(1000, this.Invest_1000);
				this.addChild(this.SubtitleJumped);
			}
		}
		/**升级血量*/
		// public UpdateHp() {
		// 	if (GameUtil.PlayerMessage.instance.money >= 200) {
		// 		GameUtil.PlayerMessage.instance.playHp += 1;
		// 		this.SubtitleJumped.SubtitleJumped(200, this.Update_Hp);
		// 		this.addChild(this.SubtitleJumped);
		// 	}
		// }
		// /**升级攻击力*/
		// public UpdateATK() {
		// 	if (GameUtil.PlayerMessage.instance.money >= 300) {
		// 		GameUtil.PlayerMessage.instance.atk += 1;
		// 		this.SubtitleJumped.SubtitleJumped(300, this.Update_ATK);
		// 		this.addChild(this.SubtitleJumped);
		// 	}
		// }
		/**切换防守方法*/
		public AddDefense() {
			this.is_AddDefenseUI = true;
		}
		/**切换敌方防守方法*/
		public AddEnemyDefense() {
			this.IS_AddEnemyDefenseUI = true;
		}
		/**弹出音乐弹窗方法*/
		public AddMusic_group() {
			this.Music_group.visible = true;
		}
		/**关闭音乐弹窗方法*/
		public CloseMusic_group() {
			this.Music_group.visible = false;
		}
		/**关闭音乐*/
		public stopMusic() {
			PrepareUI.PlayMusciBool = true;
		}
		/**打开音乐*/
		public PlayMusic() {
			PrepareUI.PlayMusciBool = false;
		}
		/**漏兵闪烁 */
		public twinkle() {		
			/** 如果基地在发射子弹 闪烁*/
			if(GameUtil.PlayerMessage.instance.is_myTurryAtk){
				this.Defense_bg.visible=true;
			}else{
				this.Defense_bg.visible=false;
			}	
			if(GameUtil.PlayerMessage.instance.is_emyTurryAtk){
				this.Enemy_bg.visible=true;
			}
			else
			{
				this.Enemy_bg.visible=false;
			}
		}
	}
}